import type { SystemMenu } from '@/api/modules/system/menu/types';
import { hasPerm } from '@/utils/common/perm';
import { DeleteOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons-vue';
import { createSubMenu, menuDelete, menuEdit } from './curd';
import { menuForm } from './form';
import { useAxTable } from '@/utils/common/hooks';

export const menuTable = useAxTable<SystemMenu>({
  rowKey: 'menuId',
  moduleName: 'SystemMenu',
  query: {
    menuName: '',
    component: '',
  },
  contextmenu: [
    {
      title: '编辑',
      label: '编辑',
      key: 'list',
      onClick() {
        menuEdit();
      },
      icon: h(EditOutlined),
      disabled: hasPerm('ax:menu:list'),
    },
    {
      title: '子菜单',
      label: '子菜单',
      key: 'create',
      icon: h(PlusOutlined),
      onClick() {
        if (menuForm.value.menuId) createSubMenu(menuForm.value.menuId);
      },
      disabled: hasPerm('ax:menu:add'),
    },
    {
      title: '删除',
      label: '删除',
      key: 'delete',
      icon: h(DeleteOutlined),
      onClick() {
        menuDelete();
      },
      disabled: hasPerm('ax:menu:remove'),
    },
  ],
});

/* 构造树形菜单 */
export const menuTree = ref();
